package com.ranjith.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ranjith.struts.form.RegisterForm;

public class RegisterAction extends Action {
	public RegisterAction() {
		System.out.println("Action object creation");
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		System.out.println("inside action");
		System.out.println(mapping.findForwards().toString());
		System.out.println(mapping.findForwardConfigs().toString());
		String[] temp = mapping.findForwards();
		for (int i = 0; i < temp.length; i++) {
			System.out.println(temp[i]);
		}
		RegisterForm registerform = (RegisterForm) form;
		System.out.println("aa: " + registerform.example);
		/*
		 * if(registerform.getExample().equalsIgnoreCase("Bobby")){
		 * System.out.println("inside if"); return
		 * mapping.findForward("example"); }
		 */
		System.out.println(registerform.example + registerform.password1
				+ registerform.password2);
		if (registerform.username != null && registerform.password1 != null
				&& registerform.password2 != null
				&& registerform.password1.equals(registerform.password2)) {
			System.out.println("session : " + request.getSession(false));
			return mapping.findForward("success");

		}
		// System.out.println(mapping.findForwards());
		// System.out.println(mapping.findForwardConfigs());
		System.out.println("session : " + request.getSession(false));

		return mapping.findForward("failure");

	}

}
